package com.yu.boot.admin.web;

import com.lhy.commonweb.model.Page;
import com.lhy.commonweb.model.RequestPage;
import com.lhy.commonweb.model.ResponseResult;
import com.lhy.commonweb.service.AbstractService;
import com.lhy.commonweb.web.BaseControllerImpl;
import com.yu.boot.admin.model.Category;
import com.yu.boot.admin.service.CategoryCoverService;
import com.yu.boot.admin.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * 内容管理
 */
@RestController
@Slf4j
@RequestMapping("category")
public class CategoryController extends BaseControllerImpl<Category, Integer> {

    public CategoryController(@Qualifier("categoryService") AbstractService service) {
        super(service);
    }

    @Autowired
    HttpServletRequest request;

    @Autowired
    CategoryCoverService categoryCoverService;

    @Override
    public Page<Category> query(@Validated @ModelAttribute RequestPage requestPage, @Validated @ModelAttribute Category bean) {
        CategoryService categoryService = getService();
        Page<Category> query = categoryService.listLike(requestPage.getPs(), requestPage.getPn(), requestPage.getSc(), bean);
        return query;
    }

    @Override
    public ResponseResult<Category> create(@RequestBody Category bean) {
        bean.setCreated(new Date());
        int add = service.add(bean);
        return ResponseResult.create(add);
    }








}
